home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / libcommon / scale.c < prev    next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  77 lines

  1. /*
  2.  * scale.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  * 
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: scale.c,v 4.0 91/07/17 14:32:08 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    scale.c,v $
  19.  * Revision 4.0  91/07/17  14:32:08  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "common.h"
  24. #include "scale.h"
  25.  
  26. TransMethods *iScaleMethods;
  27. void ScaleMatrix();
  28.  
  29. Scale *
  30. ScaleCreate()
  31. {
  32.     Scale *res;
  33.  
  34.     res = (Scale *)Malloc(sizeof(Scale));
  35.     res->x = res->y = res->z = 1.;
  36.     return res;
  37. }
  38.  
  39. TransMethods *
  40. ScaleMethods()
  41. {
  42.     if (iScaleMethods == (TransMethods *)NULL) {
  43.         iScaleMethods = (TransMethods *)Malloc(sizeof(TransMethods));
  44.         iScaleMethods->create = (TransCreateFunc *)ScaleCreate;
  45.         iScaleMethods->propagate = ScalePropagate;
  46.     }
  47.     return iScaleMethods;    
  48. }
  49.  
  50. void
  51. ScalePropagate(scale, trans, itrans)
  52. Scale *scale;
  53. RSMatrix *trans, *itrans;
  54. {
  55.     if (equal(scale->x, 0.) || equal(scale->y, 0.) || equal(scale->z, 0.))
  56.         RLerror(RL_PANIC, "Degenerate scale %g %g %g\n", scale->x, scale->y, scale->z);
  57.     ScaleMatrix(scale->x, scale->y, scale->z, trans);
  58.     /*
  59.      * Build the inverse
  60.      */
  61.     MatrixInit(itrans);
  62.     itrans->matrix[0][0] = 1. / scale->x;
  63.     itrans->matrix[1][1] = 1. / scale->y;
  64.     itrans->matrix[2][2] = 1. / scale->z;
  65. }
  66.  
  67. void
  68. ScaleMatrix(x, y, z, mat)
  69. Float x, y, z;
  70. RSMatrix *mat;
  71. {
  72.     MatrixInit(mat);
  73.     mat->matrix[0][0] = x;
  74.     mat->matrix[1][1] = y;
  75.     mat->matrix[2][2] = z;
  76. }
  77.